#include <iostream>

using std::cout;
using std::endl;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    void print()
    {
        cout << "(" << _ix
             << ", " << _iy
             << ")";
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

class Line
{
public:
    //对于类对象数据成员而言，如果不显示的初始化，会默认调用
    //子对象的默认（无参）构造函数，如果子对象没有默认的无参
    //构造函数，那么就会报错；为了完成子对象的初始化，可以在
    //初始列表中显示调用子对象的构造函数
    Line(int x1, int y1, int x2, int y2)
    : _pt1(x1, y1)
    , _pt2(x2, y2)
    {
        cout << "Line(int, int, int, int)" << endl;
    }

    void printLine()
    {
        _pt1.print();
        cout << "---->";
        _pt2.print();
        cout << endl;
    }

    ~Line()
    {
        cout << "~Line()" << endl;
    }
private:
    Point _pt1;//数据成员，子对象, 类对象数据成员
    Point _pt2;
};

int main(int argc, char *argv[])
{
    Line line(1, 2, 3, 4);
    cout << "line = ";
    line.printLine();
    cout << endl;
    return 0;
}

